package team.sun.sss.controller.log;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import team.sun.sss.dao.log.LogCourseDao;
import team.sun.sss.dao.staff.StaffDao;

import java.util.List;
import java.util.Map;

@RestController
public class LogCourseController {

    @Autowired
    LogCourseDao logCourseDao;

    @Autowired
    StaffDao staffDao;

    @GetMapping("/LogCourseList")
    public List<Map<String,Object>> LogCourseList(){
        List<Map<String,Object>> LogCourseList=logCourseDao.getLogCourseList();
        return LogCourseList;
    }

    @GetMapping("/LogStaCourseList/{log_sta}")
    public List<Map<String,Object>> LogStaCourseList(@PathVariable String log_sta){
        List<Map<String,Object>> LogStaCourseList=logCourseDao.getLogStaCourseList(log_sta);
        return LogStaCourseList;
    }
    @PostMapping("getLogStaList")
    public List<Map<String,Object>> getLogStaList(@RequestParam int userId, @RequestParam String log_course_sta){
        String log_sta = staffDao.getStaName(userId);
        List<Map<String,Object>> getLogStaList=logCourseDao.getLogStaList(log_sta,log_course_sta);
        return getLogStaList;
    }

    @GetMapping("/LogCourseList/UserId/{UserId}")
    public List<Map<String,Object>> LogStaCourseListUserId(@PathVariable int UserId){
        String log_sta = staffDao.getStaName(UserId);
        List<Map<String,Object>> LogStaCourseList=logCourseDao.getLogStaCourseList(log_sta);
        return LogStaCourseList;
    }

    @GetMapping("/logCourse_delete/{id}")
    public String logCourse_delete(@PathVariable Integer id){
        try {
            logCourseDao.deleteLogCourse(id);
        }catch (Exception e){
            System.out.println("删除失败");
            return "删除失败";
        }
        System.out.println("删除成功");
        return "删除成功";
    }


}
